<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>我的收藏</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <script src="/js/xkube.js?v=1" charset="utf-8"></script>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <table class="layui-table" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="goToDetail">详情</a>
            <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="deleteFav">取消收藏</a>
        </script>

<script type="text/html" id="currentTableBar">
  {{#  var clusterId = getQueryString("clusterId"); }}
  {{#  if (clusterId == null) { }}
  {{#      clusterId = getCookie("clusterId") }}
  {{#  } }}
    <a href="javascript:;" layuimini-content-href="page/xkube/deployDetail.html?clusterId={{clusterId}}&nameSpace={{d.nameSpace}}&deployName={{d.deployName}}" data-title="{{ d.deployName }}详情" class="layui-btn layui-btn-sm">详情</a>
    <a href="javascript:;" layuimini-content-href="page/cicd/index.html?clusterId={{clusterId}}&nameSpace={{d.nameSpace}}&cicdName={{d.deployName}}&resType=Deployment" data-title="{{ d.deployName }}流水线" class="layui-btn layui-btn-sm">CICD</a>
    <a class="layui-btn layui-btn-normal layui-btn-sm" lay-event="viewYaml">yaml编辑</a>
    <a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="restart">重启</a>
    <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delete">删除</a>
</script>

    </div>
</div>
</body>
<script>
    layui.use(['form', 'table','miniTab'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
            miniTab = layui.miniTab,
            miniTab.listen();

            form.render();

        table.render({
            elem: '#currentTableId',
            url: '/fav/v1/List',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                //{type: "checkbox", width: 50},
                {field:'id',width:80,sort: true, title: 'ID'},
      		      {field:'fav_type',sort: true, title: '类型'},
      		      {field:'cluster_id',sort: true, title: '集群ID'},
                {field:'name_space',sort: true, title: '命名空间'},
                {field:'fav_name',sort: true, title: '资源名称'},
                {field:'username',sort: true,hide:true, title: '用户'},
      		      {field:'createtime',sort: true, title: '创建时间'},
                {title: '操作', minWidth: 250, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [25, 50, 100],
            limit: 25,
            page: true
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            fav_type = data.fav_type;
            cluster_id = data.cluster_id;
            name_space = data.name_space;
            fav_name = data.fav_name;
            if( obj.event == 'goToDetail' ) {
                var srcUrl = '';
                if( fav_type == 'deploy' ) {
                  srcUrl = 'page/xkube/deployDetail.html?deployName='
                }else if( fav_type == 'pod' ) {
                  srcUrl = 'page/xkube/podDetail.html?podName='
                }else if( fav_type == 'svc' ) {
                  srcUrl = 'page/xkube/svcDetail.html?serviceName='
                }else if( fav_type == 'sts' ) {
                  srcUrl = 'page/xkube/stsDetail.html?statefulsetName='
                }else if( fav_type == 'cronjob' ) {
                  srcUrl = 'page/xkube/cronjobDetail.html?cronjobName='
                }else if( fav_type == 'cm' ) {
                  srcUrl = 'page/xkube/configmapDetail.html?configmapName='
                }else if( fav_type == 'ing' ) {
                  srcUrl = 'page/xkube/ingressDetail.html?ingressName='
                }else if( fav_type == 'app' ) {
                  srcUrl = 'page/xkube/resourceList.html?appname='
                }
                miniTab.openNewTabByIframe({
                    href:srcUrl+fav_name+'&clusterId='+cluster_id+'&nameSpace='+name_space,
                    title:fav_name+"详情",
                });                           
            }else if(obj.event == 'deleteFav') {
          			 $.ajax({
          			    url: '/fav/v1/Del?id='+data.id,
          			    type: "get",
          			    success: function (resp) {
          						 if(resp.code == 0){
          							 layer.msg('取消收藏成功', {icon: 1});
                         obj.del();
          						 }else{
          							 layer.msg(resp.msg,{icon:2});
          						 }
          				  }
          		   });
            }
        });

    });
</script>
</html>